#!/usr/bin/python
# -*- coding: utf-8 -*-
"""user auth"""

from tornado.web import RequestHandler, asynchronous, HTTPError
from tornado.auth import GoogleMixin

class AuthHandler(RequestHandler, GoogleMixin):
    @asynchronous
    def get(self):
        if self.get_argument("openid.mode", None):
            self.get_authenticated_user(self.async_callback(self._on_auth))
            return
        self.authenticate_redirect()
    
    def _on_auth(self, user):
        if not user:
            raise HTTPError(500, "Google auth failed")
        print user
        for k in user:
            print k, user[k]
# Save the user with, e.g., set_secure_cookie()